package org.pemobbe.gruo.servlets;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.write.WriteException;

import org.pemobbe.gruo.ExportServiceBean;

public class gruoxl extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req, HttpServletResponse response) throws IOException {
		try {
			/* Get Excel Data */
			ByteArrayOutputStream bytes = new ExportServiceBean().generateExcelReport();

			/* Initialize Http Response Headers */
			response.setHeader("Content-disposition", "attachment; filename=export.xls");
			response.setContentType("application/vnd.ms-excel");

			/* Write data on response output stream */
			if (bytes != null) {
				response.getOutputStream().write(bytes.toByteArray());
			}
		} catch (WriteException e) {
			response.setContentType("text/plain");
			response.getWriter().print("An error as occured");
		}

	}
}
